package com.zmz.lambda;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Create with IntelliT IDEA
 *
 * @Author: zhengmingzhe
 * @Date: 2022/07/30/19:04
 * @Description:    Lambda 表达式创建线程对象
 */
public class Lambda04 {
    public  int add(int a){
        return a+10;
    }
    public static  void mian(String [] args){
//        Runnable执行run方法无返回值  Callable执行call方法有返回值
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("创建线程");
            }
        }).start();

        //使用lambda表达式简化 因为上面的run没有参数没有返回值 new Runnable()可写为()->{}
        new Thread(
                ()->System.out.println("使用Lambda创建线程")
        ).start();

        ExecutorService executorService = Executors.newCachedThreadPool();
        //Runnable
        executorService.submit(()->{
            System.out.println("提交Runnable");
        });
        //Callable
        executorService.submit(()->{
            System.out.println("提交Callable");
            return "a";
        });
    }

}
